package com.jiazhong.example.project.bookstore.front.controller;

import com.jiazhong.example.project.bookstore.commons.bean.User;
import com.jiazhong.example.project.bookstore.commons.util.JsonResult;
import com.jiazhong.example.project.bookstore.front.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public JsonResult login(User user) {
        return userService.login(user);
    }

    @GetMapping("/is_login")
    public JsonResult isLogin(HttpServletRequest request) {
        return userService.isLogin(request.getHeader("token"));
    }

    @GetMapping("/logout")
    public JsonResult logout(HttpServletRequest request) {
        return userService.logout(request.getHeader("token"));
    }
}
